package com.yyplatform.admin.platform.log.repository;

import java.util.Date;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.yyplatform.admin.platform.log.entity.SysErrorLogEntity;


/**
 * Created on 2024-09-12
 */
public interface SysErrorLogRepository extends
        JpaRepository<SysErrorLogEntity, Long>, JpaSpecificationExecutor<SysErrorLogEntity> {

    @Query(
            value =
                    "SELECT * FROM sys_error_log WHERE 1=1 "
                            + " AND if(:username != '' , `username` = :username, 1=1 )  "
                            + " AND (create_time >= :beginDate AND create_time <= :endDate) ",
            countQuery =
                    "SELECT count(id) FROM sys_error_log WHERE 1=1 "
                            + " AND if(:username != '' , `username` = :username, 1=1 )  "
                            + " AND (create_time >= :beginDate AND create_time <= :endDate )",
            nativeQuery = true)
    Page<SysErrorLogEntity> findPage(
            @Param("username") String username,
            @Param("beginDate") Date beginDate,
            @Param("endDate") Date endDate,
            PageRequest createTime);
}
